'''
警告弹窗的常用方法：
(1)switch_to_alert().accept()
(2)switch_to.alert.accept()	建议这个
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
chrome_location = r'D:\chrom browser\chrome-win\chrome.exe'
options = webdriver.ChromeOptions()
options.binary_location = chrome_location
dr = webdriver.Chrome(options=options)
dr.get(r'https://www.baidu.com/')
dr.maximize_window()
sleep(1)

ele=dr.find_element(By.ID,'s-usersetting-top')
ActionChains(dr).move_to_element(ele).perform()
sleep(1)
dr.find_element(By.LINK_TEXT,'搜索设置').click()
sleep(1)
dr.find_element(By.LINK_TEXT,'保存设置').click()
sleep(3)
#处理警告
text=dr.switch_to.alert.text
print(text)
sleep(2)
#点击确定
dr.switch_to.alert.accept()
sleep(2)
dr.quit()